package com.hkbigdata.sybx.mapper;

import com.hkbigdata.sybx.bean.DietRecord;
import com.hkbigdata.sybx.bean.ExerciseLog;
import com.hkbigdata.sybx.bean.RestSchedule;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author liuanbo
 * @creat 2025-06-05-18:39
 * @see 2194550857@qq.com
 */
@Mapper
public interface StateMapper {
    // 饮食记录CRUD
    @Select("select diet_id as dietId, meal_type as mealType," +
            " food_name as foodName, calorie as calorie, intake_amount as intakeAmount," +
            " record_time as recordTime, notes as notes, created_at as createdAt from diet_record")
    List<DietRecord> DietRecordAll();

    @Select("select diet_id as dietId, meal_type as mealType," +
            " food_name as foodName, calorie as calorie, intake_amount as intakeAmount," +
            " record_time as recordTime, notes as notes, created_at as createdAt from diet_record where diet_id = #{dietId}")
    DietRecord getDietRecordById(Long dietId);

    @Insert("insert into diet_record (meal_type, food_name, calorie, intake_amount, record_time, notes)" +
            "values (#{mealType}, #{foodName}, #{calorie}, #{intakeAmount}, #{recordTime}, #{notes})")
    @Options(useGeneratedKeys = true, keyProperty = "dietId", keyColumn = "diet_id")
    int insertDietRecord(DietRecord dietRecord);

    @Update("update diet_record set meal_type=#{mealType}, food_name=#{foodName}, " +
            "calorie=#{calorie}, intake_amount=#{intakeAmount}, record_time=#{recordTime}, " +
            "notes=#{notes} where diet_id=#{dietId}")
    int updateDietRecord(DietRecord dietRecord);

    @Delete("delete from diet_record where diet_id=#{dietId}")
    int deleteDietRecord(Long dietId);

    // 作息记录CRUD
    @Select("select schedule_id as scheduleId, activity_type as activityType," +
            " start_time as startTime, end_time as endTime, quality_score as qualityScore," +
            " notes as notes, created_at as createdAt from rest_schedule")
    List<RestSchedule> RestScheduleAll();

    @Select("select schedule_id as scheduleId, activity_type as activityType," +
            " start_time as startTime, end_time as endTime, quality_score as qualityScore," +
            " notes as notes, created_at as createdAt from rest_schedule where schedule_id=#{scheduleId}")
    RestSchedule getRestScheduleById(Long scheduleId);

    @Insert("insert into rest_schedule (activity_type, start_time, end_time, quality_score, notes)" +
            "values (#{activityType}, #{startTime}, #{endTime}, #{qualityScore}, #{notes})")
    @Options(useGeneratedKeys = true, keyProperty = "scheduleId", keyColumn = "schedule_id")
    int insertRestSchedule(RestSchedule restSchedule);

    @Update("update rest_schedule set activity_type=#{activityType}, start_time=#{startTime}, " +
            "end_time=#{endTime}, quality_score=#{qualityScore}, notes=#{notes} where schedule_id=#{scheduleId}")
    int updateRestSchedule(RestSchedule restSchedule);

    @Delete("delete from rest_schedule where schedule_id=#{scheduleId}")
    int deleteRestSchedule(Long scheduleId);

    // 运动记录CRUD
    @Select("select exercise_id as exerciseId, activity, duration_minutes as durationMinutes," +
            " intensity, calories_burned as caloriesBurned, notes, log_date as logDate," +
            " created_at as createdAt from exercise_log")
    List<ExerciseLog> ExerciseLogAll();

    @Select("select exercise_id as exerciseId, activity, duration_minutes as durationMinutes," +
            " intensity, calories_burned as caloriesBurned, notes, log_date as logDate," +
            " created_at as createdAt from exercise_log where exercise_id=#{exerciseId}")
    ExerciseLog getExerciseLogById(Long exerciseId);

    @Insert("insert into exercise_log (activity, duration_minutes, intensity, calories_burned, notes, log_date)" +
            "values (#{activity}, #{durationMinutes}, #{intensity}, #{caloriesBurned}, #{notes}, #{logDate})")
    @Options(useGeneratedKeys = true, keyProperty = "exerciseId", keyColumn = "exercise_id")
    int insertExerciseLog(ExerciseLog exerciseLog);

    @Update("update exercise_log set activity=#{activity}, duration_minutes=#{durationMinutes}, " +
            "intensity=#{intensity}, calories_burned=#{caloriesBurned}, notes=#{notes}, log_date=#{logDate} " +
            "where exercise_id=#{exerciseId}")
    int updateExerciseLog(ExerciseLog exerciseLog);

    @Delete("delete from exercise_log where exercise_id=#{exerciseId}")
    int deleteExerciseLog(Long exerciseId);
}